package com.quesucede.gameoflife;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

/**
 * The main screen activity that operates as a listener for main menu options.
 * @author Brett Kromkamp, William Sugarman, and Brian Pokrifka
 */
public class MainActivity extends Activity implements OnClickListener {
	
	/**
	 * Called when the activity is first created.
	 * @param savedInstanceState - the saved state
	 * */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		// click-handlers for buttons
		// Settings
		View settingsButton = findViewById(R.id.settings_button);
		settingsButton.setOnClickListener(this);
		// New
		View newButton = findViewById(R.id.new_button);
		newButton.setOnClickListener(this);
		// About
		View aboutButton = findViewById(R.id.about_button);
		aboutButton.setOnClickListener(this);
		// Exit
		View exitButton = findViewById(R.id.exit_button);
		exitButton.setOnClickListener(this);
	}

	/**
	 * Listener for the buttons that dispatches work based on button id
	 * @param v - the current view
	 */
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.settings_button:
				Intent settingsIntent = new Intent(this, SettingsActivity.class);
				startActivity(settingsIntent);
				break;
			case R.id.new_button:
				Intent gridIntent = new Intent(this, GridActivity.class);
				startActivity(gridIntent);
				break;
			case R.id.about_button:
				Intent aboutIntent = new Intent(this, AboutActivity.class);
				startActivity(aboutIntent);
				break;
			case R.id.exit_button:
				moveTaskToBack(true);
				finish();
				System.gc();
				System.exit(0);		// Without killing the process, cannot terminate application directly
				break;
		}
	}
}